package com.csvreader.rss;

import java.io.IOException;


import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;





public class RssUtil {
	private Document doc;

	public String isHtmlOrXml(String url) throws IOException {
		doc = Jsoup.connect(url)

				.data("query", "Java")

				.userAgent("Mozilla")

				.cookie("auth", "token")

				.timeout(6000)

				.get();
		// System.out.print(doc.html());
		Elements head = doc.select("rss");
		if (head.size() < 1) {

			Elements rssEl = doc.select("link[type=application/rss+xml]");
			if (rssEl.size() < 1) {
				System.out.println("该地址不支持rss");
				return "eorr";

			} else {
				System.out.println("this a html   RSS地址：" + rssEl.get(0).attr("href"));
				return rssEl.get(0).attr("href");
				// 如果有多个rss地址 进行遍历
				// for(Element e:rssEl){
				// System.out.println(e.attr("title")+"----------"+e.attr("href"));
				//
				// }
			}

		} else {

			return "xml";
		}

		// return null;
	}

	public static void main(String[] args) {
		RssUtil r = new RssUtil();
		try {
			System.out.println(r.isHtmlOrXml("http://iyanlei.com/feed"));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
